$(function () {
    //注册
    $("#regist_button").click(function () {
        var name = $("#count").val().trim();
        var password1 = $("#password1").val().trim();
        var password2 = $("#password2").val().trim();
        var age = $("#age").val().trim();
        var deptid = $("#deptid").val().trim();

        var ok = true
        if (name == "") {
            ok = false;
            $("#count_span").html("用户名为空");
        }
        if (password1 == "") {
            ok = false;
            $("#password1_span").html("密码为空");
        } else {
            if (password1.length < 6) {
                ok = false;
                $("#password1_span").html("密码6位以上");
            }
        }
        if (password1 != password2) {
            ok = false;
            $("#password2_span").html("两次密码不一致");
        }
        if (age == "") {
            ok = false;
            $("#age_span").html("年龄为空");
        }
        if (deptid == "") {
            ok = false;
            $("#deptid _span").html("部门编号为空");
        }
        if (ok) {
            $.ajax({
                url:"http://localhost:80/emp/regist.do",
                type:"post",
                dataType:"json",
                data:{"ename": name, "pwd": password1, "eage": age,"deptid":deptid},
                success:function (result) {
                    if (result.status == 0){
                        alert(result.msg)
                        window.location.href = "login.jsp"//跳转登录页面
                    } else if (result.status == 1){
                        $("#count_span").html(result.msg);
                    }
                },
                error: function () {
                    alert("注册失败，稍后重试")
                }
            })
        }

    })


})